package com.xmy.study.mapper;

import com.xmy.study.entity.Shutnum;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 关数 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2023-09-08
 */
@Mapper
public interface ShutnumMapper extends BaseMapper<Shutnum> {
    @Select("select * from edu_shutnum where name = #{name} and course_id = #{course_id} and deleted=0")
    public Shutnum selectByName(@Param("name") String name, @Param("course_id") String courseId);

    @Select("select word_id from edu_unit_word where unit_id = #{unitId}")
    public List<String> getWordId(@Param("unitId") String unitId);

    @Select("select phrase_id from edu_unit_phrase where unit_id = #{unitId}")
    public List<String> getPhraseId(@Param("unitId") String unitId);


    /**
     * 查询关数名称
     *
     * @param num 关数编号
     * @return 关数名称
     */
    @Select("SELECT name FROM edu_shutnum WHERE num = #{num} LIMIT 1")
    String lowestShutNumName(@Param("num") Integer num);

    /**
     * 获取关卡数字列表
     *
     * @param courseId 课程id
     * @return
     */
    @Select("SELECT num FROM edu_shutnum WHERE course_id=#{courseId} AND deleted = 0 ")
    List<Integer> getNumList(@Param("courseId") String courseId);

    /**
     * 根据课程id获取总关数
     *
     * @param courseId
     * @return
     */
    @Select("SELECT max(num) FROM edu_shutnum WHERE course_id = #{courseId} AND deleted = 0")
    Integer getCountNum(@Param("courseId") String courseId);

    @Select("select id from edu_shutnum where  FIND_IN_SET(${unitId},unit_ids) and deleted = 0")
    List<Long> getShutnumIdList(@Param("unitId") Long unitId);
}
